/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-12-08
 * Time: 18:04
 */
class Solution1 {

    public void sortColors(int[] nums) {
        int left = -1 , right = nums.length ;
        //先把框架搭出来
        // 遍历数组
        for(int i = 0 ; i < right ; ){
            if(nums[i] == 0){
                left++;
                swap(nums,i,left);
                i++;
            }else if(nums[i] == 1){
                i++;
            }else{
                right--;
                swap(nums,i,right);
            }
        }
    }
    //交换数组中的两个元素传入数组和下标
    public void swap(int[] nums,int a , int b){
        int tem = nums[a];
        nums[a] = nums[b];
        nums[b] = tem;
    }
}
public class Test1 {
}
